﻿
function hideLoading() {
    $.mobile.loading("hide");
}

//弹出提示
function showTips(text, timeOut, callback) {
    $.mobile.loadingMessageTextVisible = true;
    $.mobile.loading('show', {
        text: text,
        textVisible: true,
        theme: 'b',
        textonly: true
    });
    if (!timeOut) {
        timeOut = 1500;
    }
    setTimeout(function () {
        hideLoading();
        if (callback) {
            callback();
        }
    }, timeOut);
}


//弹出确认对话框
function confirmDialog(text, callbackConfirm, callbackCancel) {
    if (confirm(text)) {
        callbackConfirm();
    } else {
        callbackCancel();
    }
    return;

    var popupDialogId = 'popup_confirm_dialog';
    $('<div data-role="popup" id="' + popupDialogId + '" data-confirmed="no" data-transition="pop" data-overlay-theme="b" data-theme="b" data-dismissible="false" style="max-width:500px;"> \
                        <a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn-a ui-icon-delete ui-btn-icon-notext ui-btn-right optionCancel">Close</a>\
                        <div role="main" class="ui-content">\
                        <div class="ui-title ui-bar" align="center">' + text + '</div>\
                            <div class="ui-grid-a">\
    <div class="ui-block-a"><a href="#" class="ui-btn ui-mini ui-corner-all optionConfirm" data-rel="back">确认</a></div>\
    <div class="ui-block-b"><a href="#" class="ui-btn ui-mini ui-corner-all optionCancel" data-rel="back" data-transition="flow">取消</a></div>\
</div>\
                            </div>\
                    </div>')
        .appendTo($.mobile.pageContainer);
    var popupDialogObj = $('#' + popupDialogId);
    popupDialogObj.trigger('create');
   
    popupDialogObj.popup({
        afterclose: function (event, ui) {
            popupDialogObj.find(".optionConfirm").first().off('click');
            var confirmStat = popupDialogObj.attr('data-confirmed');
            $(event.target).remove();
            if (confirmStat == 'yes' && callbackConfirm) {
                callbackConfirm();
            }
            if (confirmStat == 'no' && callbackCancel) {
                callbackCancel();
            }
        }
    });

    popupDialogObj.popup('open');
    popupDialogObj.find(".optionConfirm").first().on('click', function () {
        popupDialogObj.attr('data-confirmed', 'yes');
    });
    popupDialogObj.find(".optionCancel").first().on('click', function () {
        popupDialogObj.attr('data-confirmed', 'no');
    });
}


